package com.ymatou.iapi.sellercs.testcase;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellercs.parameter.UpdateCategoryBean;
import com.ymatou.iapi.sellercs.service.UpdateCategoryCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.SellerCSIMCallService;
import com.ymttest.database.sqlwapper.YmtSellerCSIMWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*修改话术分类
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdateCategory{
	private static UpdateCategoryBean updatecategoryBean;
	private static UpdateCategoryCall updatecategoryCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static int zsellerId = Integer.parseInt(EnvSetup.getData("autotest_seller_z"));
	private static YmtSellerCSIMWapper YmtSellerCSIMWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改话术分类");
	}

	@Before
	public void caseUp() {
		updatecategoryBean=new UpdateCategoryBean();
		updatecategoryCall=new UpdateCategoryCall();
		YmtSellerCSIMWapper=new YmtSellerCSIMWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updatecategoryCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateCategory_001() {
		Logger.start(true,"修改话术分类成功");
		try {
			String title="话术分类";
			String discourse="test";
			String CategoryId=SellerCSIMCallService.getCategoryId(sellerId, title);
			updatecategoryBean.setCategoryId(CategoryId);
			updatecategoryBean.setCSId(sellerId);
			updatecategoryBean.setSort(2);
			updatecategoryBean.setTitle(TestDataManager.getRandomUUID().toString());
			updatecategoryCall.setData(updatecategoryBean);
			updatecategoryCall.callService();			
			Logger.verifyIsContains("200", updatecategoryCall.getString("Status"), "验证Status");	
			Logger.verifyEquals(true, updatecategoryCall.getJsonObject().get("Result").getAsJsonObject().get("Success").getAsBoolean(), "验证Success");	
			List<Map>lm=YmtSellerCSIMWapper.selectIndividualdiscourseByCsid(sellerId);
			Logger.debug(CategoryId+":"+lm);
			lm = lm.stream().filter(m -> {
				if (m.get("CategoryId") != null) {
					return m.get("CategoryId").equals(CategoryId);
				} else {
					return false;
				}
			}).collect(Collectors.toList());
			for(int i=0;i<lm.size();i++){
				Logger.verifyEquals(updatecategoryBean.getTitle(),lm.get(i).get("icTitle"),"验证icTitle");
				Logger.verifyEquals(updatecategoryBean.getSort(),lm.get(i).get("icSort"),"验证icSort");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UpdateCategory_002() {
		Logger.start(true,"不输入csid失败");
		try {
			String title="话术分类";
			String CategoryId=SellerCSIMCallService.getCategoryId(sellerId, title);
			updatecategoryBean.setCategoryId(CategoryId);
//			updatecategoryBean.setCSId(sellerId);
			updatecategoryBean.setSort(2);
			updatecategoryBean.setTitle(TestDataManager.getRandomUUID().toString());
			updatecategoryCall.setData(updatecategoryBean);
			updatecategoryCall.callService();			
			Logger.verifyIsContains("400", updatecategoryCall.getString("Status"), "验证Status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UpdateCategory_003() {
		Logger.start(true,"不输入CategoryId失败");
		try {
			String title="话术分类";
			String CategoryId=SellerCSIMCallService.getCategoryId(sellerId, title);
//			updatecategoryBean.setCategoryId(CategoryId);
			updatecategoryBean.setCSId(sellerId);
			updatecategoryBean.setSort(2);
			updatecategoryBean.setTitle(TestDataManager.getRandomUUID().toString());
			updatecategoryCall.setData(updatecategoryBean);
			updatecategoryCall.callService();			
			Logger.verifyIsContains("400", updatecategoryCall.getString("Status"), "验证Status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}